<?php
/*
	Advansed MaNGOS Statistic(AMS)
	-------------------------------------------
	Author: DeusModus
	getmangos.ru
	Version: 1.1
*/
require_once("../lib/phpchartdir.php");
require_once("../inc/config.php");
include_once("../inc/mysql_connect.php");

if (isset($_GET["REALM"]))
    $selectedRealm = $_GET["REALM"];
else
    echo "ERROR! REALM.";
	
if (isset($_GET["xLabel"]))
    $selectedYear = $_GET["xLabel"];
else
    echo "ERROR! xLabel not found.";
$pagename = basename (__FILE__,".php");
# SQL statement	
$SQL = "Select max(ONLINE),MONTHNAME(TimeStamp) From ".MYSQL_DATABASE_TABLE." Where REALM ='$selectedRealm'
AND year(TimeStamp)='$selectedYear' Group By month(TimeStamp) Order By MONTH(TimeStamp)";

#
# Connect to database and read the query result into arrays
#
$result = mysql_query($SQL);

if (!$result and MYSQL_ERRORS==true) {die(MYSQL_ERROR . mysql_error());}
while ($row = mysql_fetch_row($result)) {
    $maxonline[] = $row[0];
	$month[] = $row[1];
}
#
# Now we have read data into arrays, we can draw the chart using ChartDirector
#

# Create a XYChart object of size 600 x 360 pixels
$c = new XYChart(
				 X_CHART_PIXELS,
				 Y_CHART_PIXELS
				 );

# Set the plotarea at (60, 40) and of size 480 x 280 pixels. Use a vertical gradient
# color from light blue (eeeeff) to deep blue (0000cc) as background. Set border and
# grid lines to white (ffffff).
$c->setPlotArea(
				X_PLOT_AREA_PIXELS,
				Y_PLOT_AREA_PIXELS,
				WIDTH_PLOT_AREA_PIXELS,
				HEIGHT_PLOT_AREA_PIXELS,
	$c->linearGradientColor(
					START_X_LINEAR_GRADIENT_COLOR,
					START_Y_LINEAR_GRADIENT_COLOR,
					END_X_LINEAR_GRADIENT_COLOR,
					END_Y_LINEAR_GRADIENT_COLOR,
					START_COLOR_LINEAR_GRADIENT_COLOR,
					END_COLOR_LINEAR_GRADIENT_COLOR,
					PERIODIC_LINEAR_GRADIENT_COLOR),
				ALT_BGCOLOR_PLOT_AREA,
				EDGE_COLOR_PLOT_AREA,
				H_GRID_COLOR_PLOT_AREA,
				V_GRID_COLOR_PLOT_AREA
				);

# Add a title to the chart using 18pts Times Bold Italic font
$c->addTitle(
			"".TOP_TITLE." за $selectedYear год",
			(TOP_FONT),
			TOP_FONT_SIZE,
			TOP_FONT_COLOR,
			TOP_FONT_BGCOLOR,
			TOP_FONT_EDGE_COLOR
			);

# Add a multi-color bar chart layer using the supplied data
$layer = $c->addBarLayer3($maxonline);

# Use glass lighting effect with light direction from the left
$layer->setBorderColor(Transparent, glassEffect(
												LAYER_GLARE_EFFECT,
												LAYER_GLARE_DIRECTION,
												LAYER_GLARE_RAISED_EFFECT
												)
					  );

# Set the x axis labels
$c->xAxis->setLabels($month);

# Set y-axis tick density to 30 pixels. ChartDirector auto-scaling will use this as
# the guideline when putting ticks on the y-axis.
$c->yAxis->setTickDensity(LAYER_TICK_DENSITY_Y);

# Set the y axes titles with 10pts Arial Bold font
$c->yAxis->setTitle(
					(Y_AXIS_TITLE),
					(Y_AXIS_TITLE_FONT),
					 Y_AXIS_TITLE_FONT_SIZE
					 );

$c->xAxis->setTitle(
					(X_AXIS_TITLE),
					(X_AXIS_TITLE_FONT),
					 X_AXIS_TITLE_FONT_SIZE
					 );
# Set all axes to transparent
$c->xAxis->setColors(Transparent);
$c->yAxis->setColors(Transparent);

# Set the label styles of all axes to 8pt Arial Bold font
$c->xAxis->setLabelStyle((X_AXIS_LABLE_FONT), X_AXIS_LABLE_FONT_SIZE);
$c->yAxis->setLabelStyle((Y_AXIS_LABLE_FONT), X_AXIS_LABLE_FONT_SIZE);

# Create the image
$chart1URL = $c->makeSession("chart1");

# Create an image map for the chart
$imageMap = $c->getHTMLImageMap("detail_month.php?REALM=$selectedRealm&YEAR=$selectedYear", "",
    "title='".HTML_Image_Map."{value|0}'");
include("../inc/saveimagehandler.php");
?>
<center<img src="getchart.php?<?php echo $chart1URL?>" border="0" usemap="#map1">
<map name="map1">
<?php echo $imageMap?>
</map>